<template>
  <div class="chat-content-input">
    <div class="chat-content-send">
      <el-input
        ref="chatTextarea"
        v-model.trim="sentText"
        @keyup.enter="keydownSentCon"
        :rows="2"
        type="textarea"
        maxlength="5000"
        clearable
        resize="none"
        placeholder="问题描述越详细，回答越准确哦～"
      />
      <div class="chat-content-submit">
        <div style="font-size: 14px; color: #a4a8ab">
          {{ sentText.length }}/5000
        </div>
        <div
          class="chat-content-btn"
          @click="askQuestion"
          :style="{ cursor: isLoading ? 'not-allowed' : 'pointer' }"
        >
          <img src="@/assets/images/labor/send-icon.png" alt="" />
          <span>发送</span>
        </div>
      </div>
    </div>
    <div class="chat-content-explain">
      内容由 AI 生成，请仔细甄别。
    </div>
  </div>
</template>
<script>
export default {
  name: "GptInput",
  props: {
    localChatCon: {
      type: String,
      default: "",
    },
    isLoading: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    localChatCon(val) {
      this.sentText = val;
    },
  },
  data() {
    return {
      sentText: "",
    };
  },
  mounted() {
    this.$nextTick(() => {
     // this.$ref.chatTextarea.focus();
    });
  },
  methods: {
    // 回车键发送
    keydownSentCon(context) {
      if (this.isLoading) return false;
      if (context.keyCode === 13) {
        this.$emit("sentCon", this.sentText);
        this.sentText = "";
        return false;
      }
      return true;
    },
    askQuestion() {
      if (this.isLoading) return false;
      if (!this.sentText) return this.$message.error("你没有输入内容哦");
      this.$emit("sentCon", this.sentText);
      this.sentText = "";
    },
  },
};
</script>

<style lang="less" scoped>
.chat-content-input {
  flex-shrink: 0;
  height: 170px;
  width: 100%;
  margin: 0 auto;
  padding: 0 30px;
}
.chat-content-send {
  display: flex;
  flex-direction: column;
  background-color: #fff;
  margin-top: 10px;
  border: 1px solid #acd7ff;
  box-shadow: 0px 6px 30px 5px #0000000d;
  border-radius: 10px;
  :deep(.el-textarea__inner) {
    box-shadow: none;
    color: #000;
    border-radius: 10px 10px 0 0;
    padding: 19px;
    border: none;
  }
}
.chat-content-submit {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px 9px 0;
  .chat-content-btn {
    width: 90px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(269.49deg, #0278ca 0.19%, #34b6ed 106.76%);
    border-radius: 22px;
    margin-left: 15px;
    cursor: pointer;
    > span {
      font-family: PingFang SC;
      font-size: 16px;
      font-weight: 400;
      line-height: 22.4px;
      color: #fff;
    }
    > img {
      width: 20px;
      margin-right: 6px;
    }
  }
}
.chat-content-explain {
  font-family: PingFang SC;
  font-size: 12px;
  font-weight: 500;
  line-height: 16.8px;
  color: #a4a8ab;
  margin-top: 15px;
  text-align: center;
}
</style>
